package com.itheima.exerciseTest.test50_59;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Test57 {
    public static void main(String[] args) throws IOException {
        // 创建字符输出流对象
        method1();

        // 创建字符输入对象
        method2();


    }

    private static void method2() throws IOException {
        FileReader fr = null;
        fr = new FileReader("backBurner\\b.txt");
        char[] chars = new char[1024];
        int len;
        while((len = fr.read(chars)) != -1){
            System.out.println(new String(chars,0,len));
        }
    }

    private static void method1() throws IOException {
        FileWriter fw = null;

        fw = new FileWriter(new File("backBurner\\b.txt"));
        fw.write(97);
        fw.write(98);
        fw.write(99);
        fw.write("\r\n");

        char[] chars = {97,98,99};
        fw.write(chars);
        fw.write("\r\n");

        fw.write(chars,0,2);
        fw.write("\r\n");

        fw.write("我爱java");
        fw.write("\r\n");

        String str = "我爱java";
        fw.write(str,2,4);

        fw.close();
    }
}
